package data.nametag;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;

import data.CMSRes;
import data.account.attendee.AttendeeAccount;

public class NametagGenerator
{
	public static BufferedImage genNametag(AttendeeAccount attendee, int width, int height)
	{
		String name = attendee.lastName() + ", " + attendee.firstName();
		String organization = attendee.org();
		
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = image.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

		g.setPaint(new GradientPaint(0, 0, Color.WHITE, width, height, CMSRes.Colors.get("Theme Color Light")));
		g.fillRect(0, 0, width, height);
		
		g.setPaint(Color.WHITE);
		
		Font font = CMSRes.Fonts.get("Nametag Title");
		g.setFont(font);
		
		int x = width - 100;
		int y = 100 + g.getFontMetrics().getAscent();
		g.setColor(Color.RED);
		g.drawString(name, x - g.getFontMetrics().stringWidth(name), y);

		y = height - (100 + g.getFontMetrics().getDescent());
		font = CMSRes.Fonts.get("Nametag Text");
		g.setFont(font);
		g.setColor(Color.RED.darker());
		g.drawString(organization, x - g.getFontMetrics().stringWidth(organization), y);

		g.setStroke(new BasicStroke(2.0f));
		g.setColor(Color.BLACK);
		g.draw(new RoundRectangle2D.Double(20, 20, width - 40, height - 40, 40, 40));
		
		g.setStroke(new BasicStroke(10.0f));
		g.setColor(CMSRes.Colors.get("Theme Color Dark"));
		g.draw(new RoundRectangle2D.Double(30, 30, width - 60, height - 60, 30, 30));
		
		g.setStroke(new BasicStroke(2.0f));
		g.setColor(Color.WHITE);
		g.draw(new RoundRectangle2D.Double(40, 40, width - 80, height - 80, 20, 20));
		
		g.dispose();
		
		return image;
	}
}